/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.tbp.utils;

import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

/**
 *
 * @author Diego
 */
public class Atributo {

    public static Random random = new Random();

    public static void reagirEnter(JButton btn) {
        btn.registerKeyboardAction(btn.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)), KeyStroke.getKeyStroke(
                KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);

        btn.registerKeyboardAction(btn.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)), KeyStroke.getKeyStroke(
                KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);
    }

    public static void reagirEnter(JButton... buttons) {
        for(JButton b : buttons) {
            reagirEnter(b);
        }
    }

    public static String gerarTextoAleatorio() {
        StringBuilder sb = new StringBuilder(); // ou StringBuffer no java 1.4
        sb.append('_');
        for (int i = 0; i < 26; i++) {
            char c = (char) ('a' + random.nextInt(26));
            sb.append(c);
        }

        return sb.toString();
    }

    public static void limparDiretorio(File f) {
        if (f.exists()) {
            if (f.isDirectory()) {
                for (File aFile : f.listFiles()) {
                    limparDiretorio(aFile);
                }
            }
        }
    }
}
